?><?
function setSet($name,$value){$settings=get_entity("cls_setting");$settings->set($name,$value);}
function getSet($name,$default=false){$settings=get_entity("cls_setting");if($set=$settings->get($name)){return $set->value;}else{return $default;}}
function delSet($name){$settings=get_entity("cls_setting");$settings->del($name);}
function getSetObject($name){$settings=get_entity("cls_setting");return $settings->get($name);}

class cls_setting extends cls_entity{
  function entity(){return "setting";}

  function item($id){$settings=get_entity("cls_setting");return $settings->byId($id);}

  function load(){
    if(!$this->cached()){
      $this->items=parent::get_db_items(cls_setting::entity());
      $this->cache();
    }
  }
  function get($name){    
    if($setting=$this->byName($name)){
      return $setting;
    }else{
      return false;
    }
  }

  function set($name,$value){
    if($setting=$this->byName($name)){
      if($setting->value!=$value){
        $setting->update(array("setting_value"=>$value));
        $this->changed();
      }
    }else{

      $this->insert(array(
        "setting_name"=>$name,
        "setting_value"=>$value,
			));
      $this->changed();
    }
  }

  function del($name){
    $set=$this->get($name);
    $set->delete($this->entity(),$set->id);
    $this->changed();
  }
  function insert($data){return cls_setting_item::insert($data);}

}